layui.extend({
    baseConfig : "/js/pages/baseConfig"
})
layui.use(['form','layer','laydate','table','laytpl','element','util','baseConfig'],function(){

    var form = layui.form,
    layer = parent.layer === undefined ? layui.layer : top.layer,
        baseConfig = layui.baseConfig,
        $ = layui.jquery;

    //绑定校验
    form.verify({
        quota : function(val){
            if( !val || val == ''){
                return "可用额度为必填";
            }
        },
        shoppingFlag : function(val){
            if( !val || val == ''){
                return "请选择网购是否开通";
            }
        },
    });

    //监听提交
    form.on("submit(submitBtn)",function( data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        //提交数据
        $.post( "/mooncardCard/updateQuota",{
            quota : data.field.quota,
            shoppingFlag : data.field.shoppingFlag,
            id : data.field.id
        },function( res){
            if( res.code == 200){
                setTimeout(function(){
                    top.layer.close( index);
                    top.layer.alert( res.msg);
                    layer.closeAll( "iframe");
                    //刷新父页面
                    parent.location.reload();
                },500);
            }else if( res.code == 60002){
                top.layer.close( index);
                top.layer.msg( res.msg);
            }else if( res.code == 60001){
                top.layer.close( index);
                top.layer.msg( res.msg);
            }
        });
    });
});
